﻿@using System.Web.Optimization
@using GroceryPriceBook.Infrastructure
@model GroceryPriceBook.Core.ViewModel.PurchaseLog

@{
	ViewBag.Title = "Edit";
}

@section scripts
{
	@Scripts.Render("~/bundles/form/js")
	@Scripts.Render("~/Scripts/Controllers/PurchaseLog.js")
}

<div class="row">
	<div class="large-12 columns">

		@using (Html.BeginForm("Edit", "PurchaseLog", FormMethod.Post, new { @id = "formPurchaseLog", @data_abide = "" }))
		{
			@Html.AntiForgeryToken()
			<h4>Purchase Log</h4>
			<hr />
			@Html.HiddenFor(model => model.Id)
			<div class="row">
				<div class="large-4 columns">
					<div class="row">
						<div class="large-2 small-3 columns">
							@Html.LabelFor(model => model.PurchaseDate, new { @class = "right inline" })
						</div>
						<div class="large-10 small-9 columns">
							@Html.TextBoxFor(model => model.PurchaseDate, "{0:MM-dd-yyyy}", new { @required = "", @pattern = "month_day_year" })
							<small class="error">Date is required.</small>
						</div>
					</div>
				</div>
				<div class="large-4 columns">
					<div class="row">
						<div class="large-2 small-3 columns">
							@Html.LabelFor(model => model.StoreId, "Store", new { @class = "right inline" })
						</div>
						<div class="large-10 small-9 columns">
							@Html.DropDownListFor(model => model.StoreId, Model.StoreSelectListItems, "--select one--")
							<small class="error">Select a store.</small>
						</div>
					</div>
				</div>
				<div class="large-4 columns">
					<div class="row">
						<div class="large-2 small-3 columns">
							@Html.LabelFor(model => model.TotalCost, "Total Cost", new { @class = "right inline" })
						</div>
						<div class="large-10 small-9 columns">
							@Html.TextBoxFor(model => model.TotalCost, "{0:N3}", new { @required = "", @type = "number" })
							<small class="error">Total cost be a number.</small>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<div class="row">
						<div class="large-1 small-3 columns">
							@Html.LabelFor(model => model.Note, new { @class = "right inline" })
						</div>
						<div class="large-11 small-9 columns">
							@Html.TextAreaFor(model => model.Note)
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="large-12">
					<table>
						<thead>
							<tr>
								<th>Product</th>
								<th>Total Price</th>
								<th>Quantity</th>
								<th>Price Per Item</th>
								<th>Price Per Weight / Volume Unit</th>
								<th>Price Per Count / Quantity Unit</th>
								<th>Discount?</th>
								<th>Note</th>
								<th></th>
							</tr>
						</thead>
						<tbody id="tableItems">
							@foreach (var item in Model.PurchaseLogItems)
							{
								Html.RenderPartial("_PurchaseLogItem", item);
							}
						</tbody>
					</table>
				</div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<a class="button tiny" href="#" id="addItemRow" onclick="viewModel.AddNewItem();">Add Row</a>
				</div>
			</div>
			<script type="text/x-jsrender" id="itemTemplate">
				@Html.CollectionItemJQueryTemplate("_PurchaseLogItem", new GroceryPriceBook.Core.ViewModel.PurchaseLogItem() { ProductSelectListItems = (IEnumerable<SelectListItem>)ViewBag.ProductSelectList }, new KeyValuePair<string, object>("IsCreate", ViewBag.IsCreate), null)
			</script>

			<div class="row">
				<div class="large-12">
					<button type="submit">Submit</button>
				</div>
			</div>
		}

		<div class="row">
			<div class="large-12">
				@Html.ActionLink("Back to List", "Index")
			</div>
		</div>
	</div>
</div>
